/*
 * IJA2011, Board game "Clovece nezlob se"
 * grp108
 * Tomáš Mičiak,xmicia00
 * Andrej Martinák, xmarti51
 *
 * Created on 18.4.2011, 10:01:33
 */

package src.clovece;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import src.clovece.game.GameInfo;
import src.clovece.game.GameManagement;
import src.clovece.game.Help;
import src.clovece.game.Load;

/**
 *  Class serves as the main window for the game
 */
public class GameFrame extends javax.swing.JFrame {
    private GamePanel gameBoard = null;
    private GameInfo gameInfo = GameInfo.getGameInfoInstance();
    private GameManagement gm = GameManagement.getGameManagementInstance();
    private Load load = Load.getLoadInstance();

    /** Creates new form GameBoard */
    public GameFrame() {
        super();
        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(new Point(dim.width/4,dim.height/8));
        this.setSize(1024, 768);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Menu = new javax.swing.JMenuBar();
        javax.swing.JMenu Game = new javax.swing.JMenu();
        SingleplayerMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem NewSinglePlayer = new javax.swing.JMenuItem();
        SaveSingleplayer = new javax.swing.JMenuItem();
        LoadSinglePlayer = new javax.swing.JMenuItem();
        MultiplayerMenu = new javax.swing.JMenu();
        NewMultiplayer = new javax.swing.JMenuItem();
        JoinMultiplayer = new javax.swing.JMenuItem();
        SaveMultiplayer = new javax.swing.JMenuItem();
        LoadMultiplayer = new javax.swing.JMenuItem();
        RegisterMultiplayer = new javax.swing.JMenuItem();
        GameExit = new javax.swing.JMenuItem();
        SettingsMenu = new javax.swing.JMenu();
        AiPreferences = new javax.swing.JMenuItem();
        GraphicPreferences = new javax.swing.JMenuItem();
        javax.swing.JMenuItem ServerPreferences = new javax.swing.JMenuItem();
        HelpMenu = new javax.swing.JMenu();
        HelpMenuItem = new javax.swing.JMenuItem();
        AboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Clovece");
        setResizable(false);
        getContentPane().setLayout(null);

        Menu.setName(""); // NOI18N

        Game.setText("Game");

        SingleplayerMenu.setText("Singleplayer");

        NewSinglePlayer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        NewSinglePlayer.setText("New Game");
        NewSinglePlayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NewSinglePlayerActionPerformed(evt);
            }
        });
        SingleplayerMenu.add(NewSinglePlayer);

        SaveSingleplayer.setText("Save Game");
        SaveSingleplayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveSingleplayerActionPerformed(evt);
            }
        });
        SingleplayerMenu.add(SaveSingleplayer);

        LoadSinglePlayer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        LoadSinglePlayer.setText("Load Game");
        LoadSinglePlayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadSinglePlayerActionPerformed(evt);
            }
        });
        SingleplayerMenu.add(LoadSinglePlayer);

        Game.add(SingleplayerMenu);

        MultiplayerMenu.setText("Multiplayer");

        NewMultiplayer.setText("New Game");
        NewMultiplayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NewMultiplayerActionPerformed(evt);
            }
        });
        MultiplayerMenu.add(NewMultiplayer);

        JoinMultiplayer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_J, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        JoinMultiplayer.setText("Join Game");
        JoinMultiplayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JoinMultiplayerActionPerformed(evt);
            }
        });
        MultiplayerMenu.add(JoinMultiplayer);

        SaveMultiplayer.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        SaveMultiplayer.setText("Save Game");
        MultiplayerMenu.add(SaveMultiplayer);

        LoadMultiplayer.setText("Load Game");
        LoadMultiplayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LoadMultiplayerActionPerformed(evt);
            }
        });
        MultiplayerMenu.add(LoadMultiplayer);

        RegisterMultiplayer.setText("Register");
        RegisterMultiplayer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterMultiplayerActionPerformed(evt);
            }
        });
        MultiplayerMenu.add(RegisterMultiplayer);

        Game.add(MultiplayerMenu);

        GameExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        GameExit.setText("Exit");
        GameExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GameExitActionPerformed(evt);
            }
        });
        Game.add(GameExit);

        Menu.add(Game);

        SettingsMenu.setText("Preferences");

        AiPreferences.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        AiPreferences.setText("AI Preferences");
        AiPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AiPreferencesActionPerformed(evt);
            }
        });
        SettingsMenu.add(AiPreferences);

        GraphicPreferences.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK));
        GraphicPreferences.setText("Graphic Preferences");
        GraphicPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GraphicPreferencesActionPerformed(evt);
            }
        });
        SettingsMenu.add(GraphicPreferences);

        ServerPreferences.setText("Server Preferences");
        ServerPreferences.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ServerPreferencesActionPerformed(evt);
            }
        });
        SettingsMenu.add(ServerPreferences);

        Menu.add(SettingsMenu);

        HelpMenu.setText("Help");

        HelpMenuItem.setText("Help / Documentation");
        HelpMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HelpMenuItemActionPerformed(evt);
            }
        });
        HelpMenu.add(HelpMenuItem);

        AboutMenuItem.setText("About");
        AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutMenuItemActionPerformed(evt);
            }
        });
        HelpMenu.add(AboutMenuItem);

        Menu.add(HelpMenu);

        setJMenuBar(Menu);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void NewSinglePlayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewSinglePlayerActionPerformed
        NewSingleplayerDialog ng = new NewSingleplayerDialog(this);
        ng.showYourself();
    }//GEN-LAST:event_NewSinglePlayerActionPerformed

    private void GameExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GameExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_GameExitActionPerformed

    private void AiPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AiPreferencesActionPerformed
        AiPreferencesDialog ap = new AiPreferencesDialog(this, true);
        ap.showYourself();
    }//GEN-LAST:event_AiPreferencesActionPerformed

    private void GraphicPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GraphicPreferencesActionPerformed
        GraphicPreferencesDialog gp = new GraphicPreferencesDialog(this,true);
        gp.showYourself();
    }//GEN-LAST:event_GraphicPreferencesActionPerformed

    private void RegisterMultiplayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegisterMultiplayerActionPerformed
        RegisterDialog rmd = new RegisterDialog(this, true);
        rmd.showYourself();
    }//GEN-LAST:event_RegisterMultiplayerActionPerformed

    private void NewMultiplayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NewMultiplayerActionPerformed
        NewMultiplayerDialog nmd = new NewMultiplayerDialog(this, true);
        nmd.showYourself();
    }//GEN-LAST:event_NewMultiplayerActionPerformed

    private void JoinMultiplayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JoinMultiplayerActionPerformed
            LoginDialog ld = new LoginDialog(this,true);
            ld.showYourself();
    }//GEN-LAST:event_JoinMultiplayerActionPerformed

    private void LoadMultiplayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadMultiplayerActionPerformed

    }//GEN-LAST:event_LoadMultiplayerActionPerformed

    private void LoadSinglePlayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoadSinglePlayerActionPerformed
        LoadSingleplayerGameDialog ldg = new LoadSingleplayerGameDialog(this, true);
        ldg.showYourself();
    }//GEN-LAST:event_LoadSinglePlayerActionPerformed

    private void SaveSingleplayerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveSingleplayerActionPerformed
        SaveSinglePlayerGameDialog sg = new SaveSinglePlayerGameDialog(this, true);
        sg.showYourself();
    }//GEN-LAST:event_SaveSingleplayerActionPerformed

    private void ServerPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ServerPreferencesActionPerformed
        ServerPreferencesDialog gp = new ServerPreferencesDialog(this,true);
        gp.showYourself();
    }//GEN-LAST:event_ServerPreferencesActionPerformed

    private void HelpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpMenuItemActionPerformed
        Help hlp = new Help(this);
    }//GEN-LAST:event_HelpMenuItemActionPerformed

    private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed
        AboutDialog ad = new AboutDialog(this,true);
        ad.showYourself();
    }//GEN-LAST:event_AboutMenuItemActionPerformed

 public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GameFrame().setVisible(true);
                Load load = Load.getLoadInstance();
                load.LoadSettings();
            }
        });
    }

 /*
  * Creates GamePanel containing game elements
  */
 public void fillGameFrame() {
     if(this.gameBoard != null) {
         this.remove(this.gameBoard);
         this.gameBoard.removeAll();
         this.gameBoard = null;
     }
     this.gameBoard = new GamePanel(this);
     this.gameBoard.setSize(this.getWidth(), this.getHeight());
     this.gameBoard.setLocation(0, 0);
     this.gameBoard.addMouseListener(this.gameBoard);
     this.add(this.gameBoard);
     this.repaint();
     if(this.gameInfo.getNewGame()) {
         this.gm.startNewGame();
     }
     else if(this.gameInfo.getLoadedGame()) {
         this.gm.startLoadedGame();
     }
     else if(this.gameInfo.getJoinedGame()) {
         this.gm.startJoinedGame();
     }
 }

    public GamePanel getGameBoard() {
        return this.gameBoard;
    }

    public void setGameBoard(GamePanel p) {
        this.gameBoard = p;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem AboutMenuItem;
    private javax.swing.JMenuItem AiPreferences;
    private javax.swing.JMenuItem GameExit;
    private javax.swing.JMenuItem GraphicPreferences;
    private javax.swing.JMenu HelpMenu;
    private javax.swing.JMenuItem HelpMenuItem;
    private javax.swing.JMenuItem JoinMultiplayer;
    private javax.swing.JMenuItem LoadMultiplayer;
    private javax.swing.JMenuItem LoadSinglePlayer;
    private javax.swing.JMenuBar Menu;
    private javax.swing.JMenu MultiplayerMenu;
    private javax.swing.JMenuItem NewMultiplayer;
    private javax.swing.JMenuItem RegisterMultiplayer;
    private javax.swing.JMenuItem SaveMultiplayer;
    private javax.swing.JMenuItem SaveSingleplayer;
    private javax.swing.JMenu SettingsMenu;
    private javax.swing.JMenu SingleplayerMenu;
    // End of variables declaration//GEN-END:variables
}
